//
//  WDCalendarPageCollectionView.m
//  teatCalendar
//
//  Created by 解向前 on 2018/3/6.
//  Copyright © 2018年 com.test. All rights reserved.
//

#import "WDCalendarPageCollectionView.h"
#import "WDCalendarOneDayCell.h"


static NSString *wDCalendarOneDayCellID = @"WDCalendarOneDayCell";
@interface WDCalendarPageCollectionView() <UICollectionViewDataSource, UICollectionViewDelegate>

@property (strong, nonatomic) UICollectionViewFlowLayout *flowLayout;


@end

@implementation WDCalendarPageCollectionView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame collectionViewLayout:self.flowLayout];
    if (self) {
        [self setupInit];
    }
    return self;
}

- (void)setupInit {
    // self.backgroundColor = [UIColor whiteColor];
    self.showsVerticalScrollIndicator = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.bounces = NO;
    self.delegate = self;
    self.dataSource = self;
    [self registerClass:[WDCalendarOneDayCell class] forCellWithReuseIdentifier:wDCalendarOneDayCellID];
}

- (UICollectionViewFlowLayout *)flowLayout {
    if (!_flowLayout) {
        _flowLayout = [[UICollectionViewFlowLayout alloc] init];
        _flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _flowLayout.minimumLineSpacing = 0;
        _flowLayout.minimumInteritemSpacing = 0;
    }
    return _flowLayout;
}

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    WDCalendarOneDayCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:wDCalendarOneDayCellID forIndexPath:indexPath];
    cell.model = self.models[indexPath.item];
    return cell;
}

- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.models.count;
}

- (void)setModels:(NSArray *)models {
    _models = models;
    CGFloat itemWidth = self.frame.size.width / 7.f;
    CGFloat itemHeight = self.frame.size.height / (self.models.count / 7);
    self.flowLayout.itemSize = CGSizeMake(itemWidth, itemHeight);
    [self reloadData];
}


@end
